﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OneShoppingDAL;
using OneShoppingBLL;
using OneShoppingUtility;
using OneShoppingModel;

public partial class Backstage_Pages_sysmng_roleManager : BaseListPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (role.RoleId != 1)
        {
            Response.Redirect("login.html");
        }
        PageSize = 10;
        TableName = "Role"; Pk = "RoleId";
        if (!this.IsPostBack)
        {
            PageIndex = 0;
            BindData(ref rptList);
            BindAspNetPager(ref Pager);
        }
    }
    protected void Pager_PageChanged(object sender, EventArgs e)
    {
        PageIndex = Pager.CurrentPageIndex - 1;
        BindData(ref rptList);
    }
    public string getStatus(object statu)
    {
        string result = "未知";
        bool s = Convert.ToBoolean(statu);
        if(s)
        {
            result = "启用中";
        }
        else
        {
            result = "<font color='red'>已禁用</font>";
        }
        return result;
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("roleAdd.aspx");
    }
    protected void btndelete_Click(object sender, EventArgs e)
    {
        string[] id = SelectId();
        if (id != null)
        {
            foreach (var i in id)
            {
                int rid = Convert.ToInt32(i);
                var t = RoleBLL.GetInstance().GetEntity(r => r.RoleId == rid);
               t.IsUsing = t.IsUsing == 1 ? 0 : 1;
                RoleBLL.GetInstance().Update(t);
            }
            BindData(ref rptList);
            BindAspNetPager(ref Pager);
        }
    }
    private string[] SelectId()
    {
        string[] id = null;
        string ids = "";
        try
        {
            ids = Request["ids"];
            if (ids.Length == 0)
            {
                UtilityMessageBox.Show(this, "未选择");
                return null;
            }
        }
        catch 
        {
            UtilityMessageBox.Show(this, "未选择");
            return null;
        }
        id = ids.Split(',');
        return id;
    }
}